package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.serivce.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;

    /**
     * 发布视频
     *   post
     *   请求参数：
     *     两个文件：videoThumbnail-图片（客户端根据视频自动生成的封面图），videoFile-视频
     */
    @PostMapping
    public ResponseEntity smallVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideosService.saveVideos(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询视频列表
     *    get
     *    参数：page,pagesize
     *    返回值：PageResult  -- 封装List<VideosVo>
     */
    @GetMapping
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize) {
        //1、调用service
        PageResult vo = smallVideosService.findVideos(page,pagesize);
        //2、返回
        return ResponseEntity.ok(vo);
    }

    /**
     * 视频点赞
     *   POST       /smallVideos/:id/like
     */
    @PostMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String videoId) {
        smallVideosService.like(videoId);
        return ResponseEntity.ok(null);
    }

}
